home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Softshoe / Lisa's Mac Parts / Pascal Strings / ConstPString.h < prev    next >
Text File  |  2000-06-23  |  1KB  |  51 lines

  1. // ConstPString.h
  2.  
  3. #ifndef ConstPString_h
  4. #define ConstPString_h
  5.  
  6. #ifndef ConstData_h
  7. #include "ConstData.h"
  8. #endif
  9.  
  10. class ConstPString
  11.   {
  12.     private:
  13.         const uint8 *string;
  14.     
  15.         operator=( const ConstPString& );    // This method intentionally left undefined.
  16.             
  17.     public:
  18.         ConstPString( const uint8 *s )
  19.           : string( s )
  20.           {
  21.             Assert( s != 0 );
  22.           }
  23.  
  24.         uint8 Length() const                                        { return string[0]; }
  25.         const URange32 Range() const                            { return URange32( 0, Length() ); }
  26.         
  27.         const uint8& operator[]( uint32 i ) const
  28.             { Assert( i < Length() ); return string[i+1]; }
  29.         
  30.         const ConstData Text() const                            { return ConstData( string+1, Length() ); }
  31.         const ConstData Head( uint32 size ) const            { return Text().Head( size ); }
  32.         const ConstData Tail( uint32 position ) const    { return Text().Tail( position ); }
  33.         const ConstData Middle( URange32 range ) const    { return Text().Middle( range ); }
  34.  
  35.         operator const uint8 *() const                        { return string; }
  36.         operator ConstData() const                                { return Text(); }
  37.   };
  38.  
  39.  
  40. bool operator==( ConstPString a, ConstPString b );
  41. bool operator< ( ConstPString a, ConstPString b );
  42. bool operator<=( ConstPString a, ConstPString b );
  43.  
  44. inline bool operator!=( ConstPString a, ConstPString b )        { return !(a == b); }
  45. inline bool operator> ( ConstPString a, ConstPString b )        { return !(a <= b); }
  46. inline bool operator>=( ConstPString a, ConstPString b )        { return !(a < b); }
  47.  
  48. int32 Compare( ConstPString a, ConstPString b );
  49.  
  50. #endif
  51.